var e = require("../../@babel/runtime/helpers/regeneratorRuntime"),
  t = require("../../@babel/runtime/helpers/asyncToGenerator"),
  n = require("../../utils/http.js"),
  a = require("../../utils/api.js"),
  i = require("../../utils/language/switchLanguage.js");
Page({
  data: {
    dataH: 0,
    museumMerchant: {},
    TicketConfig: {},
    isTeam: !1,
    checkTeam: !1,
    languageType: "",
  },
  onLoad: function (e) {
    wx.getStorageSync("language") || wx.setStorageSync("language", 0),
      this.initLanguage(),
      a.isExitOpenId("plugin://order/index-page");
    var t = wx.getMenuButtonBoundingClientRect();
    this.setData({
      dataH: t.top + t.height + 10,
      skey: e.skey,
      openId: requireMiniProgram().getOpenId(),
    }),
      wx.setStorageSync("skey", e.skey),
      this.getOpenId();
  },
  initLanguage: function () {
    var e = i.languageVersion(wx.getStorageSync("language"));
    this.setData({ _t: e, languageType: wx.getStorageSync("language") });
  },
  switchLanguage: function (e) {
    "english" == e.target.dataset.language
      ? i.changLanguage(0)
      : i.changLanguage(1),
      this.initLanguage();
  },
  goback: function () {
    wx.navigateBack({
      fail: function (e) {
        wx.switchTab({ url: "/pages/index/index" });
      },
    });
  },
  getTicketConfig: function () {
    var e = this;
    n.getTicketConfig({ sourceType: 1 }).then(function (t) {
      e.setData({
        TicketConfig: t.data,
        isOpenTeamAppointment: t.data.isOpenTeamAppointment,
      });
    });
  },
  getOpenId: function () {
    var e = this,
      t = {
        appNo: "wx393d60d93f70599c",
        openId: this.data.openId,
        configType: 1,
        loginType: 2,
        accessToken: this.data.skey,
      };
    n.threeWayLogin(t).then(function (t) {
      if (null == t.uid)
        return (
          a.showMsg(e.data._t["登录过期，请重新登录"]),
          void wx.navigateTo({
            url: "/pages/mine-index/login/index?redirectUrl=".concat(
              encodeURIComponent("plugin://order/index-page"),
              "&type=4",
            ),
          })
        );
      console.log(t, "resresres"),
        e.setData({
          museumMerchant: t.museumMerchant,
          isTeam: t.isTeam,
          teamType: t.teamType,
        }),
        wx.setStorageSync("token", t.token),
        wx.setStorageSync("openId", t.openId),
        wx.setStorageSync("uid", t.uid),
        wx.setStorageSync("telphoneNumber", t.contactsPhone),
        wx.setStorageSync("museumMerchant", t.museumMerchant),
        wx.setStorageSync("merchantNo", t.museumMerchant.merchantNo),
        e.getTicketConfig();
    });
  },
  toPage: function (e) {
    switch (e.currentTarget.dataset.type) {
      case "fit":
        wx.navigateTo({
          url: "plugin-private://wx393d60d93f70599c/pages/Visiting/index",
        });
        break;
      case "team":
        if (0 != this.data.isOpenTeamAppointment)
          return void a.showMsg("暂未开放");
        if (!this.data.isTeam) return void this.setData({ checkTeam: !0 });
        wx.navigateTo({
          url: "plugin-private://wx393d60d93f70599c/pages/Visiting/index?type=".concat(
            this.data.teamType,
          ),
        });
    }
  },
  imOk: function () {
    this.setData({ checkTeam: !1 });
  },
  turingSDKInit: function (n) {
    var a = this;
    return t(
      e().mark(function t() {
        return e().wrap(function (e) {
          for (;;)
            switch ((e.prev = e.next)) {
              case 0:
                return (e.next = 2), requireMiniProgram().turingSDKInit();
              case 2:
                e.sent, a.getDeviceToken();
              case 4:
              case "end":
                return e.stop();
            }
        }, t);
      }),
    )();
  },
  getDeviceToken: function (n) {
    return t(
      e().mark(function t() {
        return e().wrap(function (e) {
          for (;;)
            switch ((e.prev = e.next)) {
              case 0:
                return (e.next = 2), requireMiniProgram().getDeviceToken();
              case 2:
                e.sent;
              case 3:
              case "end":
                return e.stop();
            }
        }, t);
      }),
    )();
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
});
